#include <stdio.h>

#define SHM_QUEUE_IMPLEMENTATION
#include "shm_queue.h"

int main() {
  shm_queue_t rqueue;
  shm_queue_options_t options;
  options.elem_count = 128;
  options.elem_size = 1024;
  options.mode = SHM_QUEUE_MODE_READ;
  options.name = "test";

  int rslt = shm_queue_open(&rqueue, &options);
  printf("shm_queue_open ret:%d\n", rslt);

  char buffer[1024];

  while (1) {
    rslt = shm_queue_read(&rqueue, buffer, sizeof(buffer));
    if (rslt > 0) {
      printf("shm_queue_read msgid:%d size:%d \n", rqueue.rmsgid, rslt);
    } else {
      //printf("shm_queue_read ret:%d\n", rslt);
      usleep(100000);
    }
  }
  printf("finish\n");
  shm_queue_close(&rqueue);
  return 0;
}
